package com.panshi.service.impl;

import com.panshi.constant.Constant;
import com.panshi.dao.IPariseDao;
import com.panshi.service.IPariseService;
import com.panshi.vo.PariseVO;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.HashMap;
import java.util.Map;
@Service
public class IPariseServiceImpl implements IPariseService {

    @Resource
    private IPariseDao iPariseDao;


    @Override
    public Map<String, Object> addParise(PariseVO pariseVO) {

        Map<String, Object> map = new HashMap<>();

        boolean flag = this.checkPaarise(pariseVO);

        if(flag){
            iPariseDao.addParise(pariseVO);

            this.updatePariseCount(pariseVO.getId());

            map.put("status",true);
            map.put("msg","成功");
        }else {
            map.put("status",false);
            map.put("msg","已点赞");
        }


        return map;
    }

    @Override
    public boolean checkPaarise(PariseVO pariseVO) {

        PariseVO temp = iPariseDao.checkParise(pariseVO);

        if (temp == null){
            return true;
        }

        return false;
    }


    @Override
    public void updatePariseCount(String id) {

        iPariseDao.updatePariseCount(id);
    }
}
